package cn.wen.yinxiu.works.service.impl;

import cn.wen.yinxiu.common.enums.DelEnum;
import cn.wen.yinxiu.common.enums.StatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.wen.yinxiu.common.toolkit.PageUtils;
import cn.wen.yinxiu.common.toolkit.Query;

import cn.wen.yinxiu.works.dao.AudioDao;
import cn.wen.yinxiu.works.entity.AudioEntity;
import cn.wen.yinxiu.works.service.AudioService;


@Service("audioService")
@Component
public class AudioServiceImpl extends ServiceImpl<AudioDao, AudioEntity> implements AudioService {

    @Autowired
    private AudioDao audioDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AudioEntity> page = this.page(
                new Query<AudioEntity>().getPage(params),
                new QueryWrapper<AudioEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public AudioEntity queryAudioById(Long audioId) {
        QueryWrapper<AudioEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", audioId);
        queryWrapper.eq("status", StatusEnum.NORMAL_USE.code());
        queryWrapper.eq("is_deleted", DelEnum.NORMAL.code());
        return audioDao.selectOne(queryWrapper);
    }

}